/**
 * 只要将层序遍历的结果倒序即可
 * @function {queue}
*/

const levelOrderBottom = root => {
  const res = [],
    queue = []
  if (!root) return res
  queue.push(root)
  while (queue.length) {
    let len = queue.length
    const curArr = []

    for (let i = 0; i < len; i++) {
      const node = queue.shift()
      // console.log(node, 'nnnnnnnn');
      curArr.push(node.val)
      node.left && queue.push(node.left)
      node.right && queue.push(node.right)
    }
    res.push(curArr)
  }
  return res
}

const root = {
  val: 3,
  left: {
    val: 9,
    left: null,
    right: null
  },
  right: {
    val: 20,
    left: {
      val: 15,
      left: null,
      right: null
    },
    right: {
      val: 7,
      left: null,
      right: null
    }
  }
}

console.log(levelOrderBottom(root));